package payroll.trans;

import payroll.Employee;
import payroll.PayrollDatabase;
import payroll.classfication.HourlyClassification;
import payroll.classfication.PaymentClassfication;
import payroll.classfication.TimeCard;
import payroll.exception.NoSuchEmployeeException;
import payroll.exception.NotHourlyClassificationException;

public class TimeCardTransaction implements Transaction {

    private int empId;
    private String date;
    private double hours;

    public TimeCardTransaction(int empId, String date, double hours) {
        this.empId = empId;
        this.date = date;
        this.hours = hours;
        
    }

    @Override
    public void execute() {
        //根据雇员编号取雇员对象
        Employee e = PayrollDatabase.getEmployee(empId);
        if (e== null) {
            throw new NoSuchEmployeeException();
            
        }
        //取计算工资方式
        PaymentClassfication pc = e.getPaymentClassification();
        if (pc instanceof HourlyClassification) {
            
            HourlyClassification hc = (HourlyClassification) pc;
            //为钟点工员登记一个时间卡
            TimeCard tc = new TimeCard(date,hours);
            hc.addTimeCard(tc);
        
    }else {
        throw new NotHourlyClassificationException();
    }

}
}